<template>
  <el-button type="danger" @click="delPlan" v-if="showButton" :loading="loading">撤销计划</el-button>
</template>

<script>
import {deleteShippingPlan} from "@/api/shippingPlan";

export default {
  name: 'DelPlanButton',
  props: {
    id: {
      required: true
    },
    data: {
      type: Object,
    },
  },
  computed: {
    showButton(){
      if(!this.data){
        return false
      }
      const arr = ['saved', 'ready_to_ship',]
      return arr.includes(this.data.status)
    }
  },
  data(){
    return {
      loading: false,
    }
  },
  methods: {
    delPlan(){
      this.$confirm('','确认撤销计划?')
        .then(res=>{
          deleteShippingPlan(this.data.id)
            .then(res=>{
              if(res.error === 0){
                this.$successMessage(res.message)
                this.$emit('changeRow')
                this.$emit('delRow')
              }
            })
        })
        .catch(res=>{
          console.log(res)
        })
    },
  }
}

</script>

<style scoped lang="scss">

</style>
